<template>
  <div>
    <swiper class="swiper">
      <swiper-slide v-for="(page,index) in iconPages" :key="index">
        <ul class="icon">
          <li v-for="(item,index) in page" :key="index"><img :src="item.iconImg"><br>
            <span>{{item.iconTitle}}</span>
          </li>
        </ul>
      </swiper-slide>
    </swiper>
  </div>
</template>
<script>
export default {
  name: 'homeIcon',
  props: {
    iconList: Array
  },
  data () {
    return {
      swiperOption: {
        autoplay: false
      }
    }
  },
  computed: {
    iconPages () {
      const pages = []
      this.iconList.forEach((item, index) => {
        const page = Math.floor(index / 8) // Math.floor()取整
        if (!pages[page]) {
          // pages[page]为undefined ,if语句中显示为false     !false为true
          pages[page] = []
        }
        pages[page].push(item)
      })
      return pages
    }
  }
}
</script>
<style lang="stylus" scoped>
.icon {
  width: 100%;
}

.icon li {
  float: left;
  width: 25%;
  text-align: center;
}

.icon li img {
  width: 50px;
  margin: 0 auto;
}
</style>
